package cn.shangjia.shop.controller.mod;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.shangjia.common.dao.support.Page;
import cn.shangjia.common.domain.NewsComment;
import cn.shangjia.common.domain.NewsOnline;
import cn.shangjia.common.util.StringUtils;
import cn.shangjia.shop.controller.base.AbstractController;
import cn.shangjia.shop.service.NewsService;
/**
 * @description 企业动态控制器
 * @author <a href="mailto:wangxin@knet.cn">wangxin</a>
 * @version 
 * @date 2011-11-03 上午10:34:16
 */
@Controller
public class CompanyNewsMod extends AbstractController {
	
	@Resource
	private NewsService newsService;
	
	/**
	 *  企业动态页面
	 * 
	 * @param userid
	 * @param pageNo
	 * @param type
	 * @param model
	 * @return
	 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
	 */
	@RequestMapping("/shop/module/companyNews/index.html")
	public String mod_companyNews(ModelMap model, String pageNo,String userid) {
		Page<NewsOnline> page = newsService.findNewsPage(userid, getInt(pageNo), config.getNewsCurrentPagesize());
		model.addAttribute("page", page);
		return "shop/module/companyNews/index";
	}
	
	/**
	 *  详细页面
	 * 
	 * @param model
	 * @param userid
	 * @param id
	 * @return
	 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
	 */
	@RequestMapping("/shop/module/companyNews/detail.html")
	public String mod_companyNews_detail(ModelMap model, String userid, String id) {
		
		if (StringUtils.isEmpty(id))
			return mod_companyNews(model, "1", userid);
		
		NewsOnline news = newsService.getNews(id);
		
		if (news == null) 
			return mod_companyNews(model, "1", userid);
		
		model.addAttribute("newsInfo", news);
		
		return "shop/module/companyNews/detail";
	}
	
	/**
	 *  评论页
	 * 
	 * @param model
	 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
	 */
	@RequestMapping("/shop/module/companyNews/comment.html")
	public void mod_company_news_comment(ModelMap model, String userid, String id, String pageNo) {
		if (StringUtils.isEmpty(id))
			return ;
		int pageNum = getInt(pageNo);
		int pageSize = config.getNewsCommentPagesize();
		 Page<NewsComment> commentPage = newsService.getCommentPage(id, pageNum, pageSize);
		 model.addAttribute("page", commentPage);
	}
}
